package me.jessyan.armscomponent.app.mvp.ui.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.jess.arms.base.BaseFragment;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;

import butterknife.BindView;
import butterknife.OnClick;
import me.jessyan.armscomponent.commonsdk.core.RouterHub;
import me.jessyan.armscomponent.commonsdk.core.User;
import me.jessyan.armscomponent.commonsdk.utils.Utils;
import me.jessyan.armscomponent.app.R;
import me.jessyan.armscomponent.app.di.component.DaggerMineHomeComponent;
import me.jessyan.armscomponent.app.mvp.contract.mine.MineHomeContract;
import me.jessyan.armscomponent.app.mvp.presenter.mine.MineHomePresenter;

import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * <p>
 * Author: Taozebi
 * Date: 08/16/2021 21:35
 * Description: describe of this class
 */

@Route(path = RouterHub.MINE_HOMEFRAGMENT)
public class MineHomeFragment extends BaseFragment<MineHomePresenter> implements MineHomeContract.View {

    @BindView(R.id.mine_tv_username)
    TextView mine_tv_username;

    public static MineHomeFragment newInstance() {
        MineHomeFragment fragment = new MineHomeFragment();
        return fragment;
    }

    @Override
    public void setupFragmentComponent(@NonNull AppComponent appComponent) {
        DaggerMineHomeComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public View initView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.mine_fragment_home, container, false);
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        mPresenter.getUser();
    }

    @Override
    public void setData(@Nullable Object data) {

    }

    @OnClick({R.id.mine_iv_setting,
            R.id.mine_tv_recommendation,R.id.mine_tv_receiving_address,R.id.mine_tv_my_group,R.id.mine_tv_achievements,
            R.id.mine_tv_msg_center,R.id.mine_tv_my_notes,R.id.mine_tv_help_center,R.id.mine_tv_collection,
            R.id.mine_tv_reward,R.id.mine_tv_history, R.id.learning_list_ly, R.id.mine_rl_study_report})
    public void onClicked(View view){
        int id = view.getId();
        if(id == R.id.mine_iv_setting){
            if(Utils.isFastClick()){
                //设置
                ARouter.getInstance().build(RouterHub.MINE_SETTINGACTIVITY).navigation();
            }
        }else if(id == R.id.mine_tv_recommendation){
            if(Utils.isFastClick()){
                //推荐
                ARouter.getInstance().build(RouterHub.MINE_RECOMMENDATIONACTIVITY).navigation();
            }
        }else if(id == R.id.mine_tv_receiving_address){
            if(Utils.isFastClick()){
                //收货地址
                ARouter.getInstance().build(RouterHub.MINE_RECEIVINGADDRESSACTIVITY).navigation();
//                showMessage("收货地址");
            }
        }else if(id == R.id.mine_tv_my_group){
            if(Utils.isFastClick()){
                //我的群组
//                ARouter.getInstance().build(RouterHub.MINE_ACHIEVEMENTSACTIVITY).navigation();
                showMessage("我的群组");
                ARouter.getInstance().build(RouterHub.USER_TESTKNOWLEDGELEVELACTIVITY).navigation();
            }
        }else if(id == R.id.mine_tv_achievements){
            if(Utils.isFastClick()){
                //成就
                ARouter.getInstance().build(RouterHub.MINE_ACHIEVEMENTSACTIVITY).navigation();
            }
        }else if(id == R.id.mine_tv_msg_center){
            if(Utils.isFastClick()){
                //消息中心
                ARouter.getInstance().build(RouterHub.MINE_MSGCENTERACTIVITY).navigation();
            }
        }else if(id == R.id.mine_tv_my_notes){
            if(Utils.isFastClick()){
                //我的笔记
                ARouter.getInstance().build(RouterHub.MINE_MYNOTESACTIVITY).navigation();
//                showMessage("我的笔记");
            }
        }else if(id == R.id.mine_tv_help_center){
            if(Utils.isFastClick()){
                //帮助中心
                ARouter.getInstance().build(RouterHub.MINE_HELPCENTERACTIVITY).navigation();
//                showMessage("帮助中心");
            }
        }else if(id == R.id.mine_tv_collection){
            if(Utils.isFastClick()){
                //收藏
                ARouter.getInstance().build(RouterHub.MINE_COLLECTIONACTIVITY).navigation();
//                showMessage("收藏");
            }
        }else if(id == R.id.mine_tv_reward){
            if(Utils.isFastClick()){
                //奖励
                ARouter.getInstance().build(RouterHub.MINE_REWARDACTIVITY).navigation();
            }
        }else if(id == R.id.mine_tv_history){
            if(Utils.isFastClick()){
                //历史
                ARouter.getInstance().build(RouterHub.MINE_HISTORYACTIVITY).navigation();
            }
        } else if(id == R.id.learning_list_ly) {
            if(Utils.isFastClick()){
                //学习榜单
                ARouter.getInstance().build(RouterHub.MINE_LEARNINGLISTACTIVITY).navigation();
            }
        } else if(id == R.id.mine_rl_study_report){
            if(Utils.isFastClick()){
                //学习报告
                ARouter.getInstance().build(RouterHub.MINE_STUDYREPORTACTIVITY).navigation();
            }
        }

    }


    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showMessage(@NonNull String message) {
        checkNotNull(message);
        ArmsUtils.snackbarText(message);
    }

    @Override
    public void launchActivity(@NonNull Intent intent) {
        checkNotNull(intent);
        ArmsUtils.startActivity(intent);
    }

    @Override
    public void killMyself() {

    }

    @Override
    public void setUserInfo(User user) {
        if(user != null){
            mine_tv_username.setText(user.getNickname());
        }
    }
}
